package logic

import (
	"context"
	"person/models"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 完善信息
func (l *PerfectLogic) Perfect(in *personrpc.PerfectRequest) (*personrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	user := models.User{
		Mobile:   in.Mobile,
		Password: in.Password,
		Address:  in.Address,
		RealName: in.RealName,
	}

	if err := user.UserUpdates(models.DB, in.Mobile); err != nil {
		return nil, err
	}

	return &personrpc.PerfectResponse{
		UserId: int64(user.ID),
	}, nil
}
